from web_practice.page_object.wx_base_page import BasePage
from web_practice.page_object.wx_contact_page import WxContactPage


class WxAddMemberPage(BasePage):
    _save_member = ('CSS', '.qui_btn.ww_btn.js_btn_save')
    _cancel_member = ('CSS', '.qui_btn.ww_btn.js_btn_cancel')
    _save_to_continue_add_member = ('CSS', '.qui_btn.ww_btn.ww_btn_Blue.js_btn_continue')
    _add_member = ('CSS', '.qui_btn.ww_btn.js_add_member')
    _username = ('ID', 'username')
    _english_name = ('ID', 'memberAdd_english_name')
    _acctid = ('ID', 'memberAdd_acctid')
    _phone = ('ID', 'memberAdd_phone')
    _name__error_tips = ('CSS','.ww_inputWithTips_tips')

    def goto_contact(self):
        """
        跳转通讯录页面
        :return:
        """

        return WxContactPage(self.web_driver)

    def save_member(self):
        """
        保存操作
        :return:
        """

        self.find_web_element(*self._save_member).click()

    def cancel_member(self):
        """
        取消操作
        :return:
        """
        self.find_web_element(*self._cancel_member).click()

    def save_to_continue_add_member(self):
        """
        保存并继续添加操作
        :return:
        """
        self.find_web_element(*self._save_to_continue_add_member).click()

    def add_member_success(self, **kwargs):
        """
        添加成员成功
        :param kwargs:
        :return:
        """
        self.find_web_element(*self._username).send_keys(kwargs['username'])
        self.find_web_element(*self._english_name).send_keys(kwargs['english_name'])
        self.find_web_element(*self._acctid).send_keys(kwargs['acctid'])
        self.find_web_element(*self._phone).send_keys(kwargs['phone'])
        self.save_member()
        return WxContactPage(self.web_driver)

    def add_member_fail(self, issave = False, **kwargs):
        """
        添加成员失败
        :param issave: 是否保存
        :param kwargs:
        :return:
        """
        self.find_web_element(*self._username).send_keys(kwargs['username'])
        self.find_web_element(*self._english_name).send_keys(kwargs['english_name'])
        self.find_web_element(*self._acctid).send_keys(kwargs['acctid'])
        self.find_web_element(*self._phone).send_keys(kwargs['phone'])
        if issave is True:
            self.save_member()
        error_tips = [i.text for i in self.find_web_elements(*self._name__error_tips) if  i.text !=""]
        return error_tips
